﻿using News.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace News.VariableTemplate
{
    public class VariableTiles : DataTemplateSelector
    {
        public DataTemplate SmallTemplate { get; set; }
        public DataTemplate BigTemplate { get; set; }
        public DataTemplate LengthyTemplate { get; set; }
        public DataTemplate SquareTemplate { get; set; }
        public DataTemplate WideTemplate { get; set; }
        public DataTemplate NormalTemplate { get; set; }
        public DataTemplate SemanticsSmallTemplate { get; set; }
        public DataTemplate SemanticsBigTemplate { get; set; }

        protected override Windows.UI.Xaml.DataTemplate SelectTemplateCore(object item, Windows.UI.Xaml.DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;
            if (item is HubPageDataItem)
            {

                if (item.GetType() == typeof(HubPageDataItem))
                {
                    if ((item as HubPageDataItem).UniqueId.StartsWith("Small"))
                        return SmallTemplate;
                    if ((item as HubPageDataItem).UniqueId.StartsWith("Big"))
                        return BigTemplate;
                    if ((item as HubPageDataItem).UniqueId.StartsWith("Length"))
                        return LengthyTemplate;
                    if ((item as HubPageDataItem).UniqueId.StartsWith("Square"))
                        return SquareTemplate;
                    if ((item as HubPageDataItem).UniqueId.StartsWith("Wide"))
                        return WideTemplate;
                    if ((item as HubPageDataItem).UniqueId.StartsWith("Normal"))
                        return NormalTemplate;
                }
            }
            else if (item.GetType() == typeof(SemanticDataItem))
            {
                
                if (item != null && element != null)
                {
                    if ((item as SemanticDataItem).UniqueId.StartsWith("SemanticsSmall"))
                        return SemanticsSmallTemplate;
                    if ((item as SemanticDataItem).UniqueId.StartsWith("SemanticsBig"))
                        return SemanticsBigTemplate;
                }
            }
            return base.SelectTemplateCore(item, container);
        }
    }
    
}

